package org.kwin.common.util;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @author : wangkai
 * @version V1.0
 * @Package org.kwin.common.util
 * @Description:
 * @date 2021年09月28日 11:04
 **/
public class RefectUtil {
    
    public static <T> T newInstance(String clzzName) {
        
        if(clzzName == null) {
            return null;
        }
        Class clzz = null;
        try {
            clzz = Class.forName(clzzName);
        } catch(ClassNotFoundException e) {
            e.printStackTrace();
        }
        if(clzz == null) {
            return null;
        }
        
        
        return newInstance(clzz);
    }
    
    public static <T> T newInstance(Class clzz) {
        
        if(clzz == null) {
            return null;
        }
        
        Constructor con = null;
        T result = null;
        try {
            con = clzz.getConstructor();
            result = (T) con.newInstance();
        } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) {
            ex.printStackTrace();
        }
        
        return result;
    }
}
